﻿
@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_Index.cshtml";
}

<div class="topPanel">
    @Html.Partial("_OrganizeIdDDLToolbarSearchView")
    <div class="toolbar">
        <div class="btn-group">
            <a id="NF-add" authorize="yes" class="btn btn-primary" onclick="btn_add()"><i class="fa fa-plus"></i>新建</a>
        </div>
        <div class="btn-group">
            <a id="NF-edit" class="btn btn-primary" onclick="btn_edit()"><i class="fa fa-pencil-square-o"></i>修改</a>
        </div>
    </div>
    <div class="search">
        <table>
            <tr>
                <td>
                    <div class="input-group">
                        <input id="txt_keyword" type="text" class="form-control" placeholder="名称" style="width: 180px;">
                        <span class="input-group-btn">
                            <button id="btn_search" type="button" class="btn  btn-primary"><i class="fa fa-search"></i></button>
                        </span>
                    </div>
                </td>
            </tr>
        </table>
    </div>
</div>
<div class="gridPanel">
    <table id="gridList"></table>
</div>

<script>
    $(function () {
        initControl();
        gridList()
    })
    function gridList() {
        var $gridList = $("#gridList");
        $gridList.dataGrid({
            treeGrid: true,
            treeGridModel: "adjacency",
            ExpandColumn: "dlCode",
            postData: { keyword: $("#txt_keyword").val(), organizeId: $("#OrganizeId").val() },
            url: "/ChargeCategory/GetTreeGridJson",
            height: $(window).height() - 128,
            colModel: [
                 { label: "主键", name: "dlId", hidden: true, key: true },
                    { label: '名称', name: 'dlmc', width: 150, align: 'left' },
                  { label: "编码", name: "dlCode", width: 100, align: 'left' },
                 {
                     label: "门诊住院标志", name: "mzzybz", width: 100, align: "left",
                    formatter: function (cellvalue) {
                        if (cellvalue == "0") {
                            return "通用"
                        } else if (cellvalue == "1") {
                            return "门诊"
                        } else {
                            return "住院"
                        }
                    }
                 },
            {
                label: "大类类别", name: "dllb", width: 100, align: "left",
                formatter: function (cellvalue) {
                    if (cellvalue == "1") {
                        return "药品"
                    }
                    else if (cellvalue == "2") {
                        return "治疗项目"
                    }
                    else if (cellvalue == "3") {
                        return "非治疗项目"
                    }
                    else {
                        return ""
                    }
                }
                },
				{ label: '所属分类', name: 'fjmc', width: 100, align: 'left' },
				{
					label: '税率', name: 'sn', width: 40, align: 'left', formatter: function (cellvalue) {
						if (cellvalue == null) {
							return 0
						}
						else {
							return cellvalue
						}
						
					}},
                { label: "有效", name: "zt", width: 80, align: "left", formatter: function (cellvalue) { return cellvalue == "1" ? "<i class=\"fa fa-toggle-on\"></i>" : "<i class=\"fa fa-toggle-off\"></i>"; } },
                { label: '创建人', name: 'CreatorCode', width: 100, align: 'left' },
                { label: '创建时间', name: 'CreateTime', width: 100, align: 'left', formatter: "date", formatoptions: { srcformat: 'Y-m-d', newformat: 'Y-m-d' } },
                { label: '最后修改', name: 'LastModifierCode', width: 100, align: 'left' },
                { label: '最后修改时间', name: 'LastModifyTime', width: 100, align: 'left', formatter: "date", formatoptions: { srcformat: 'Y-m-d', newformat: 'Y-m-d' } },
                { label: '排序', name: 'px', width: 85, align: 'left' }
            ],
        });
        $("#btn_search").click(function () {
            $("#gridList").jqGrid('setGridParam', {
                postData: { keyword: $("#txt_keyword").val(), organizeId: $("#OrganizeId").val() },
            }).trigger('reloadGrid');
        });
    }

    //回车事件
    $('#txt_keyword').keydownEnterEvent(function () {
        $('#btn_search').trigger('click');
    })

    function initControl() {

    }

    function btn_add() {
        $.modalOpen({
            id: "Form",
            title: "新增大类",
            url: "/ChargeCategory/Form?orgId=" + $('#OrganizeId').val(),
            width: "550px",
            height: "700px",
            callBack: function (iframeId) {
                top.frames[iframeId].submitForm();
            }
        });
    }

    function btn_edit() {
        var seleRowid = jQuery("#gridList").jqGrid("getGridParam", "selrow");
        if (!(seleRowid)) {
            $.modalAlert("请选中一条信息", 'warning');
            return;
        }
        var keyValue = $("#gridList").jqGridRowValue().dlId;
        $.modalOpen({
            id: "Form",
            title: "修改大类",
            url: "/ChargeCategory/Form?keyValue=" + keyValue,
            width: "550px",
			height: "700px",
            callBack: function (iframeId) {
                top.frames[iframeId].submitForm();
            }
        });
    }

</script>

